<?php
// +----------------------------------------------------------------------
// | Wendasns [ 开源问答社区系统 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020~2021 http://wendasns.com All rights reserved.
// +----------------------------------------------------------------------
namespace app\wendasns\admin;

use app\admin\AdminBaseController;
use app\wendasns\model\Comment as byComment;

class Comment extends AdminBaseController
{
	public function index()
    {
    	return view();
    }
    
    public function list()
    {
    	$limit = input('get.limit',20,'intval');
		$dm = byComment::order('create_time','desc')->paginate($limit);
		foreach($dm as $k=>$v){
			$dm[$k]->username = isset($v->users->username)?$v->users->username:'';
		}
        $data = $dm->toArray();
		success('ok', $data['data'], ['count'=>$data['total']]);
    }

	public function edit()
	{
		$id = input('get.id',0,'intval');
		$dm = byComment::find($id);
		success('操作成功');
	}
	
	public function check()
	{
		$id = input('post.id',[]);
		if(is_array($id)){
			$dm = byComment::select($id);
			$dm->update(['status'=>'normal']);
		}
		success('操作成功');
	}
	
	public function remove()
	{
		$id = input('post.id',[]);
		if(is_array($id)){
			$dm = byComment::select($id);
			$dm->update(['remove'=>1]);
		}
		success('操作成功');
	}
	
	public function delete()
	{
		$id = input('post.id',[]);
		if(is_array($id)){
			byComment::destroy($id);
		}
		success('操作成功');
	}
}